package com.czl.lunt.controller;

import com.czl.lunt.common.Result;
import com.czl.lunt.common.ResultCode;
import com.czl.lunt.model.Board;
import com.czl.lunt.service.BoardService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/board")
public class BoardController {

    private static final Logger log = LoggerFactory.getLogger(BoardController.class);
    @Autowired
    private BoardService boardService;
    @Operation(description = "顶部文章信息")
    @GetMapping("/topList")
    public Result<List<Board>> topList(){
        //这里的9瞎写的 可以写在配置文件里面
        List<Board> boards = boardService.selectByNum(9);
        if(boards == null){
            log.info("顶部帖子为空");
            return Result.failed(ResultCode.FAILED_BOARD_BANNED);
        }
        return Result.success(boards);
    }
    @Operation(description = "详细查询某个帖子")
    @GetMapping("/getById")
    public Result<Board> getById(@NonNull Long id){
        Board board = boardService.selectById(id);
        if (board == null || board.getState() != 0 || board.getDeleteState() != 0){
            return Result.failed(ResultCode.FAILED_BOARD_NOT_EXISTS);
        }
        return Result.success(board);

    }
}
